C
C     ..................................................................
C
C        SUBROUTINE DTEUL
C
C        PURPOSE
C           COMPUTE THE SUM OF FCT(K) FOR K FROM ONE UP TO INFINITY.
C
C        USAGE
C           CALL DTEUL(FCT,SUM,MAX,EPS,IER)
C           PARAMETER FCT REQUIRES AN EXTERNAL STATEMENT.
C
C        DESCRIPTION OF PARAMETERS
C           FCT    - NAME OF AN EXTERNAL DOUBLE PRECISION FUNCTION
C                    SUBPROGRAM USED. IT COMPUTES THE K-TH TERM OF THE
C                    SERIES TO ANY GIVEN INDEX K.
C           SUM    - RESULTANT VALUE IN DOUBLE PRECISION CONTAINING ON
C                    RETURN THE SUM OF THE GIVEN SERIES.
C           MAX    - INPUT VALUE, WHICH SPECIFIES THE MAXIMAL NUMBER
C                    OF TERMS OF THE SERIES THAT ARE RESPECTED.
C           EPS    - SINGLE PRECISION INPUT VALUE, WHICH SPECIFIES THE
C                    UPPER BOUND OF THE RELATIVE ERROR.
C                    SUMMATION IS STOPPED AS SOON AS FIVE TIMES IN
C                    SUCCESSION THE ABSOLUTE VALUE OF THE TERMS OF THE
C                    TRANSFORMED SERIES ARE FOUND TO BE LESS THAN
C                    EPS*(ABSOLUTE VALUE OF CURRENT SUM).
C           IER    - RESULTANT ERROR PARAMETER CODED IN THE FOLLOWING
C                    FORM
C                     IER=0  - NO ERROR
C                     IER=1  - REQUIRED ACCURACY NOT REACHED WITH
C                              MAXIMAL NUMBER OF TERMS
C                     IER=-1 - THE INTEGER MAX IS LESS THAN ONE.
C
C        REMARKS
C           NO ACTION BESIDES ERROR MESSAGE IN CASE MAX LESS THAN ONE.
C
C        SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
C           THE EXTERNAL FUNCTION SUBPROGRAM FCT(K) MUST BE FURNISHED
C           BY THE USER.
C
C        METHOD
C           EVALUATION IS DONE BY MEANS OF A SUITABLY REFINED EULER
C           TRANSFORMATION. FOR REFERENCE, SEE
C           F.B.HILDEBRAND, INTRODUCTION TO NUMERICAL ANALYSIS,
C           MCGRAW/HILL, NEW YORK/TORONTO/LONDON, 1956, PP.155-160, AND
C           P. NAUR, REPORT ON THE ALGORITHMIC LANGUAGE ALGOL 60,
C           CACM, VOL.3, ISS.5 (1960), PP.311.
C
C     ..................................................................
C
      SUBROUTINE DTEUL (FCT,SUM,MAX,EPS,IER)
C
      DIMENSION Y(15)
      DOUBLE PRECISION FCT,SUM,Y,AMN,AMP
C
C        TEST ON WRONG INPUT PARAMETER MAX
C
      IF(MAX)1,1,2
    1 IER=-1
      GOTO 12
C
C        INITIALIZE EULER TRANSFORMATION
C
    2 IER=1
      I=1
      M=1
      N=1
      Y(1)=FCT(N)
      SUM=Y(1)*.5D0
C
C        START EULER-LOOP
C
    3 J=0
    4 I=I+1
      IF(I-MAX)5,5,12
    5 N=I
      AMN=FCT(N)
      DO 6 K=1,M
      AMP=(AMN+Y(K))*.5D0
      Y(K)=AMN
    6 AMN=AMP
C
C        CHECK EULER TRANSFORMATION
C
      IF(DABS(AMN)-DABS(Y(M)))7,9,9
    7 IF(M-15)8,9,9
    8 M=M+1
      Y(M)=AMN
      AMN=.5D0*AMN
C
C        UPDATE SUM
C
    9 SUM=SUM+AMN
      IF(ABS(SNGL(AMN))-EPS*ABS(SNGL(SUM)))10,10,3
C
C        TEST END OF PROCEDURE
C
   10 J=J+1
      IF(J-5)4,11,11
   11 IER=0
   12 RETURN
      END
